package org.cjprods.icerupt;

import com.hackoeur.jglm.*;

import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.system.MathUtil;

import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL12.*;
import static org.lwjgl.opengl.GL13.*;
import static org.lwjgl.opengl.GL14.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL21.*;
import static org.lwjgl.opengl.GL30.*;
import static org.lwjgl.opengl.GL31.*;
import static org.lwjgl.opengl.GL32.*;
import static org.lwjgl.opengl.GL33.*;

import java.io.IOException;
import java.nio.FloatBuffer;

public class program
{
	public int id;
	public static int current_id = 0;
	
	public program(String name) throws IOException
	{
		id = utils.make_prog(name);
	}
	
	public void uniform(String name, float x)
	{
		use();
		glUniform1f(glGetUniformLocation(id, name), x);
	}
	
	public void uniform(String name, float x, float y)
	{
		use();
		glUniform2f(glGetUniformLocation(id, name), x, y);
	}
	
	public void uniform(String name, Mat3 x)
	{
		use();
		float m[] = new float[9];
		FloatBuffer b = x.getBuffer();
		b.get(m);
		b.flip();
		b = BufferUtils.createFloatBuffer(9);
		b.put(m);
		b.flip();
		glUniformMatrix3fv(glGetUniformLocation(id, name), false, b);
	}
	
	public void uniform(String name, int x)
	{
		use();
		glUniform1i(glGetUniformLocation(id, name), x); 
	}
	
	public void uniform(String name, Vec3 x)
	{
		use();
		glUniform3f(glGetUniformLocation(id, name), x.getX(), x.getY(), x.getZ());
	}
	
	public void use()
	{
		if (current_id == id) return;
		current_id = id;
		glUseProgram(id);
	}
}
